package cn.com.infohold.smartcity.api.converter;

import com.google.gson.Gson;

import java.io.Serializable;
import java.lang.reflect.Type;

import cn.com.infohold.smartcity.api.GsonUtils;
import library.http.Converter;


/**
 * Created by Mr.Fan on 2017/3/25.
 */

public class JsonConverter implements Converter<String, Serializable> {
    private final Gson gson = GsonUtils.getGson();

    public JsonConverter() {
    }

    @Override
    public String[] getContentTypes() {
        return new String[]{"json", "application/json", "text/json", "text/plain", null};
    }

    @Override
    public Serializable convert(String data, Type actualType) throws Throwable {
        return gson.fromJson(data, actualType);
    }

    public Gson getGson() {
        return gson;
    }
}
